home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / GETCATAL.C < prev    next >
C/C++ Source or Header  |  1992-05-30  |  3KB  |  110 lines

  1. #include    <MacTypes.h>
  2. #include    <OSUtil.h>
  3. #include    <MemoryMgr.h>
  4. #include    <FileMgr.h>
  5. #include    <ResourceMgr.h>
  6. #include    <pascal.h>
  7. #include    <hfs.h>
  8. #include    <string.h>
  9. #include     "HyperXCmd.h"
  10. #include    "HyperUtils.h"
  11.  
  12. /*** If you read this column    ***/
  13. /*** column on a regular basis    ***/
  14. /*** you may want to add these    ***/
  15. /*** routines to HyperUtils.c    ***/
  16. /***                            ***/
  17. /*** If you don't have Hyper-    ***/
  18. /*** utils.c, you can obtain it    ***/
  19. /*** from MacTutor for a small    ***/
  20. /*** handling charge            ***/
  21.  
  22.  
  23. #define        SYNC    0
  24.  
  25. AppendCharToHandle( theHand, theChar )
  26.     Handle    theHand;
  27.     char    theChar;
  28. /****************************
  29. *
  30. * Given a valid handle, append
  31. * the character passed in to 
  32. * the end of the handle
  33. * This is a useful way to embed
  34. * \r, \t or \0 into a container
  35. * for use by hypercard.
  36. ****************************/
  37. {
  38.     long        hsiz = GetHandleSize( theHand );
  39.     char        *dirP;
  40.  
  41.      SetHandleSize( theHand, hsiz + 1 );
  42.      dirP = *theHand + hsiz;
  43.      *dirP= theChar;
  44. }
  45.  
  46.  
  47.  
  48. GetCatalog( wdref, dirH )
  49.     short        wdref;
  50.     Handle        dirH;
  51. /****************************
  52. * Get a listing of the directory
  53. * passed in.
  54. *
  55. * In:
  56. *     wdref == reference number of the
  57. *             the desired working directory
  58. *
  59. *    dirH == handle to the output container.
  60. *
  61. * Note that we allocate all structures 
  62. * in the heap to minimize the impact
  63. * a high directory valence might have
  64. * on the stack.
  65. ****************************/
  66. {
  67.     OSErr        done    = 0;            /* goes true when done searching    */
  68.     CInfoPBPtr    catPB    = (CInfoPBPtr)NewPtr( sizeof(CInfoPBRec));
  69.     WDPBPtr        wdPB    = (WDPBPtr)NewPtr( sizeof(WDPBRec));
  70.     char        *fname    = (char *)NewPtr( 256L );
  71.  
  72.     DebugStr("\pget cat");
  73.     if( catPB && wdPB && fname ){
  74.         catPB->dirInfo.ioNamePtr     = (StringPtr)fname;
  75.         catPB->dirInfo.ioFDirIndex     = 0;
  76.         catPB->dirInfo.ioVRefNum    = wdref;            
  77.         
  78.         do{
  79.             *(catPB->dirInfo.ioNamePtr) = '\0';
  80.             catPB->dirInfo.ioFDirIndex++;
  81.             catPB->dirInfo.ioDrDirID    = 0; 
  82.             
  83.             if( (done = PBGetCatInfo( catPB, SYNC ) ) == noErr ){
  84.                 pStrToField( fname, '', dirH );
  85.                  if( catPB->dirInfo.ioFlAttrib & 0x010 ){    /*** it's a directory    ***/
  86.                     AppendCharToHandle( dirH, ':' );
  87.                     
  88.                     /*
  89.                     wdPB->ioNamePtr     = NIL; 
  90.                      wdPB->ioWDProcID     = 0;
  91.                     wdPB->ioWDVRefNum    = catPB->dirInfo.ioVRefNum;
  92.                     wdPB->ioWDDirID     = catPB->dirInfo.ioDrDirID; 
  93.                     
  94.                     if( PBOpenWD( wdPB, SYNC) == noErr ){
  95.                         GetCatalog( catPB->dirInfo.ioVRefNum, dirH);
  96.                         PBCloseWD( wdPB, SYNC );
  97.                     }
  98.                     */
  99.                  }
  100.                  AppendCharToHandle( dirH, '\r' );
  101.             }
  102.         }while( !done );
  103.         
  104.         DisposPtr( (Ptr)catPB );
  105.         DisposPtr( (Ptr)wdPB );
  106.         DisposPtr( (Ptr)fname );
  107.     }
  108. }
  109.